// 白名单：无需登录即可访问的页面路径
const whiteList = ['/pages/login/login', '/pages/index/index'];

// 检查登录状态
function checkAuth() {
  return !!wx.getStorageSync('token');
}

// 封装路由方法
module.exports = {
  navigateTo: function (options) {
    if (checkAuth() || whiteList.includes(options.url)) {
      wx.navigateTo(options);
    } else {
      wx.redirectTo({ url: '/pages/login/login' });
    }
  },
  redirectTo: function (options) {
    if (checkAuth() || whiteList.includes(options.url)) {
      wx.redirectTo(options);
    } else {
      wx.redirectTo({ url: '/pages/login/login' });
    }
  },
  reLaunch: function (options) {
    if (checkAuth() || whiteList.includes(options.url)) {
      wx.reLaunch(options);
    } else {
      wx.reLaunch({ url: '/pages/login/login' });
    }
  },
  switchTab: function (options) {
    // switchTab 页面默认加入白名单（如需拦截可调整）
    wx.switchTab(options);
  }
};